package com.yuqih.common.json;

import org.bson.types.ObjectId;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;

@Deprecated
public class JacksonObjectMapper {
	
	/**
	 * 注意：该对象不要做任何形式的修改参数操作
	 */
	
	public static final ObjectMapper Default_Object_Mapper = JacksonObjectMapper
			.newDefaultObjectMapperInstance();

	public static ObjectMapper newDefaultObjectMapperInstance(boolean failOnUnknownProperties) {
		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.configure(
				DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, failOnUnknownProperties);
		objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
		// objectMapper.setSerializationInclusion(Include.NON_NULL);
		// objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); 
		
//		try {
//			Thread.currentThread().getContextClassLoader().loadClass("org.bson.types.ObjectId");
//			SimpleModule objectIdModule = new SimpleModule();  
//			objectIdModule.addSerializer(ObjectId.class, new ObjectIdJsonSerializer()); 
//			objectIdModule.addDeserializer(ObjectId.class, new ObjectIdJsonDeserializer());
//			objectMapper.registerModule(objectIdModule);
//		} catch (ClassNotFoundException ignore) {
//			
//		}
		
		return objectMapper;
	}
	
	public static ObjectMapper newDefaultObjectMapperInstance() {
		return newDefaultObjectMapperInstance(false);
	}

}
